package controler.states;
import controler.A_State;
import controler.userCommands.AddToSelection;
import controler.userCommands.ChangeUserViewPoint;
import controler.userCommands.SwitchState;
import graphic.RenderObject;
import view.events.LevelEditorViewMouseEvent;
import view.events.LevelEditorViewOtherEvent;

/**
 * @author Damien Mabin
 */

class Initial extends A_State
{

	public function new() 
	{
		super();
		this.addEventListener(LevelEditorViewMouseEvent.EVENT, OnLevelEditorMouseEvent);
		this.addEventListener(LevelEditorViewOtherEvent.EVENT, OnLevelEditorViewOtherEvent);
	}
	
	private function OnLevelEditorViewOtherEvent(_Evt:LevelEditorViewOtherEvent):Void
	{
		switch(_Evt.m_Type)
		{
			case SELECT_RENDER_OBJECT_FOR_CREATION(name, file) :
			{
				var state : CreateRenderObject = cast A_State.s_Controller.CREATE_RENDER_OBJECT;
				state.SetRenderObjectToClone(name, file);
				A_State.s_Controller.DoUserCommand(new SwitchState(A_State.s_Controller.CREATE_RENDER_OBJECT));
			}
			default :
			{
				
			}
		}
	}
	
	private function OnLevelEditorMouseEvent(_Evt:LevelEditorViewMouseEvent):Void
	{
		switch(_Evt.m_Type)
		{
			case MOUSE_DOWN :
			{
				switch(_Evt.m_TargetType)
				{
					case RENDER_OBJECT :
					{
						if(!A_State.s_Controller.m_KeyboardKeyState[32/*space*/])
						{
							#if debug
								trace("Add RenderObject to selection");
							#end
							if (A_State.s_Controller.m_KeyboardKeyState[17/*Ctrl*/])
							{
								A_State.s_Controller.DoUserCommand(new AddToSelection(A_State.s_Controller.MULTIPLE_SELECTION, RenderObject, _Evt.m_Target));
							}
							else
							{
								A_State.s_Controller.DoUserCommand(new AddToSelection(A_State.s_Controller.SIMPLE_SELECTION, RenderObject, _Evt.m_Target));
							}
						}
					}
					default :
					{
						
					}
				}
			}
			case MOUSE_MOVE :
			{
				if (A_State.s_Controller.m_KeyboardKeyState[32/*space*/])
				{
					A_State.s_Controller.DoUserCommand(new ChangeUserViewPoint(null, _Evt.m_MouseMovement.x, _Evt.m_MouseMovement.y, 0));
				}
			}
			case MOUSE_UP :
			{
				
			}
			case MOUSE_WHEEL :
			{
				if(_Evt.m_DeltaWheel < 0)
				{
					A_State.s_Controller.DoUserCommand(new ChangeUserViewPoint(null, 0, 0, A_State.s_Model.VUE_GetZoomLevel() * 0.2));
				}
				else
				{
					A_State.s_Controller.DoUserCommand(new ChangeUserViewPoint(null, 0, 0, -A_State.s_Model.VUE_GetZoomLevel() * 0.2));
				}
			}
		}
	}
	
}